﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Browser;
using System.Xml.Linq;
using SilverQuery;

namespace SilverQueryDemo
{
	public class BasicSamples : SilverQueryComponent
	{
		public override void ready()
		{
			@q("#button1").click(e =>
			{
				@q("h3").css("color", "red").css("text-decoration", "underline");
				return false;
			});

			@q("#listBuilderDemo input[type=button]").click(e =>
			{
				var count = @q("#listBuilderDemo ul").children("li").length;

				@q("<li/>").html("list item " + (count + 1)).appendTo("#listBuilderDemo ul");
				return false;
			});

			@q("#restServiceDemo input[type='button']").click(e =>
				{
					DownloadFeed();
					return false;
				});

			@q("#showHideDemo input[type='button']").click(e =>
				{
					var container = @q("#showHideDemo");
					var status = @q("termtip.status", container);
					var elem = @q("h3", container);

					if (elem.isMatch(":hidden"))
						elem.fadeIn("500", () => status.html("Fade In Complete"));
					else
						elem.fadeOut("500", () => status.html("Fade out Complete"));

					return false;
				});
		}

		private void DownloadFeed()
		{
			Ajax.get("http://services.digg.com/stories/topic/apple", 
				new map(){{ "count",3}, {"appkey", "http://localhost"}},
				(response, error) => @q("#restServiceDemo textarea").val(response));
		}
	}
}
